package com.jiehoo.elove.robot;

import java.io.IOException;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import rath.msnm.MSNMessenger;

public class Robot {
	private static Log log = LogFactory.getLog(Robot.class);
	private MSNMessenger messanger;

	private Configuration configuration;

	public Robot(Configuration configuration) {
		this.configuration = configuration;
	}

	public void login() {
		messanger = new MSNMessenger(
				configuration.getString("robot.loginname"), configuration
						.getString("robot.password"));
		messanger.setInitialStatus(configuration.getString("robot.initstatus"));
		messanger.addMsnListener(new BaseAdapter(messanger));
		messanger.login();
		try {
			messanger.setMyFriendlyName(configuration.getString("robot.name"));
		} catch (IOException e) {
			log.error("Failded set friendly name", e);
		}
	}

	public void logout() {
		messanger.logout();
	}
}